package com.itheima.controller;

import com.itheima.pojo.Attendance;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.pojo.User;
import com.itheima.service.AttendanceService;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/attendance")
@Validated
public class AttendanceController {
    @Autowired
    private AttendanceService attendanceService;

    @GetMapping
    public Result<PageBean<Attendance>> list(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) Integer userId
    ) {
        PageBean<Attendance> pb = attendanceService.getDaysReportsForMember(pageNum, pageSize, userId );
        return Result.success(pb);
    }

    //打卡签到
    @GetMapping("/check-in")
    public Result checkIn(@RequestParam(required = false) Integer userId) {
        System.out.println(userId);

        attendanceService.checkIn(userId);
        return Result.success();
    }

    @GetMapping("/check-out")
    public Result checkOut(@RequestParam(required = false) Integer userId) {
        attendanceService.checkOut(userId);
        return Result.success();
    }
}
